"use strict";
/**
 * @author zhaojiuyi
 * @date 2022/9/23-18:07
 * @version 1.0.0
 */
import api from "@/apis/api"
import util from "@/util/util"
export default {
  state: {
    userInfo: {
      id: "000001",
      realName: "该用户未登录",
      sex: "男",
      age: 21,
      idCard: "575294383011310403"
    },
    medicalRecords:[]
  },
  getters:{
    getUserInfo(state){
      return state
    },
    getMedicalRecordInfo(state){

    }
  },
  mutations: {
    setUserInfo: (state,userinfo) => {
      state.userInfo = userinfo
    },
    setMedicalRecords(state,data){
      state.medicalRecords = data
    },
    cleanUserInfo: (state) => {
      state.userInfo.realName = "用户未登录"
      state.userInfo.id = "000001"
      state.userInfo.sex = "未知"
      state.userInfo.age = "100"
      state.userInfo.idCard = "500000000000000001"
      localStorage.clear()
    }
  },
  actions:{
    async setUserInfo ({commit}) {
      const result = await api.getUserInfo()
      if (result.code === 200){
        const {data} = result
        commit("setUserInfo",data)
      }else {
        util.errorMessage(result.msg)
      }
    },
    async getMedicalRecord({commit}) {
      const result = await api.getUserMediaList()
      if (result.code === 200){
        commit("setMedicalRecords",result.data.list)
      }else{
        util.errorMessage(result.msg)
      }
    },
    async userReportError(context,{id,remark}){
      const result = await api.reportError(id,remark)
      if (result.code === 200) {
        return "success"
      }else{
        util.errorMessage(result.msg)
      }
    }
  }
}
